version: '3'

services:

  database:
    image: postgresql
    build:
      context: ./database
      dockerfile: Dockerfile
    container_name: database
    ports:
      - "5432:5432"
    restart: always
    networks:
      - lab8net
    environment:
      - POSTGRES_USER=dbuser
      - POSTGRES_PASSWORD=123
      - POSTGRES_HOST=localhost
      - POSTGRES_DATABASE=pensione
    volumes:
      - dbvolume:/var/lib/postgresql
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:5432" ]
      interval: 30s
      timeout: 10s
      retries: 5

  Backend:
    image: backend
    command: python manage.py runserver 0.0.0.0:8000
    #      - python manage.py migrate
    build:
      context: ./Backend
      dockerfile: Dockerfile
    #    entrypoint: ./entrypoint.sh
    container_name: container_backend
    networks:
      - lab8net
    ports:
      - 8000:8000
    volumes:
      - backendvolume:/Backend
    restart: on-failure
    depends_on:
      - database
    links:
      - database
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000"]
      interval: 30s
      timeout: 10s
      retries: 5

networks:
  lab8net:

volumes:
  backendvolume:
  dbvolume:
